/*
 * Created on 2005/4/12
 *
 */
package com.erp.app.util.popupSearchTemplate;

import java.util.HashMap;

import com.erp.common.web.SearchResultRow;

public abstract class PopupSearchTemplateFactory {
    private static HashMap registry = new HashMap();

    protected PopupSearchTemplateFactory(String id) {
        registry.put(id, this);
    }

    // Static initialization block in which we initialize all concrete factory
    // implementations extending this class
    // *note* this should be the only place you should modify everytime you
    // create a new concrete implemenation of this class
    static {
        DefaultPopupSearchTemplate.init();
        VendorPopupSearchTemplate.init();
        CustomerPopupSearchTemplate.init();
        ItemPopupSearchTemplate.init();
    }

    public abstract void execute(PopupSearchTemplateComponent comp);

    public static PopupSearchTemplateFactory create(String templateId) {
        PopupSearchTemplateFactory factory = (PopupSearchTemplateFactory) registry.get(templateId);

        if (factory == null) {
            System.out.println("Failed to create PopupSearchTemplate(Id:" + templateId + ")");
            factory = (PopupSearchTemplateFactory) registry.get("default");
        }

        return factory;
    }

    public abstract Object getSearchResultValue(SearchResultRow row);

    public abstract Object getSearchResultLabel(SearchResultRow row);
}
